from sqlalchemy import Column, Integer, String, DateTime, func, Boolean
from sqlalchemy.ext.declarative import declared_attr


class BaseEntity:
    @declared_attr
    def gmt_created(self):
        return Column("gmt_created", DateTime, default=func.now(), comment="创建时间")

    @declared_attr
    def created_by(self):
        return Column("created_by", String(50), comment="创建人")

    @declared_attr
    def gmt_modified(self):
        return Column("gmt_modified", DateTime, onupdate=func.now(), comment="修改时间")

    @declared_attr
    def modified_by(self):
        return Column("modified_by", String(50), comment="修改人")

    @declared_attr
    def deleted(self):
        return Column("deleted", Boolean, default=False, comment="是否删除")

    @declared_attr
    def version(self):
        return Column("version", Integer, default=0, comment="版本")
